#include "hero.h"

hero::hero()
{

}

hero &hero::getinstance()
{
    static hero h;
    return h;
}

void hero::init()
{
    level=1;
    _hp=1000;
    _attack=10;
    _defend=10;
    money=0;
    exp=0;
    keyB=1;
    keyR=1;
    keyY=1;
    maxFloor=1;
    hasPan=true;
    hasQuery=false;
    hasPick=false;
    hasTen=false;
    fairyTalk=true;
    stealTalk=true;
    prinessTalk=true;
    path="://images/8.png";
}

void hero::move(int row,int col)
{
    _row=row;
    _col=col;
}

void hero::levelUp(int num)
{
    level+=num;
    _attack+=num*10;
    _defend+=num*10;
    _hp+=num*1000;
}

void hero::pick(stage &s)
{
    if(s.isGet)
        return ;
    switch (s._type) {
    case 61:
        keyR+=1;
        QMessageBox::information(nullptr,"道具","获得一把红钥匙");
        break;
    case 62:
        keyY+=1;
        QMessageBox::information(nullptr,"道具","获得一把黄钥匙");
        break;
    case 63:
        keyB+=1;
        QMessageBox::information(nullptr,"道具","获得一把蓝钥匙");
        break;
    case 64:
        _hp+=500;
        QMessageBox::information(nullptr,"道具","血量+500");
        break;
    case 65:
        _hp+=200;
        QMessageBox::information(nullptr,"道具","血量+200");
        break;
    case 66:
        _defend+=3;
        QMessageBox::information(nullptr,"道具","获得蓝宝石，防御力+3");
        break;
    case 67:
        _attack+=3;
        QMessageBox::information(nullptr,"道具","获得红宝石，攻击力+3");
        break;
    case 68:
        _attack+=10;
        QMessageBox::information(nullptr,"道具","获得铁剑，攻击力+10");
        break;
    case 69:
        _defend+=20;
        QMessageBox::information(nullptr,"道具","获得铁盾，防御力+20");
        break;
    case 70:
        keyB+=1;
        keyR+=1;
        keyY+=1;
        QMessageBox::information(nullptr,"道具","获得钥匙包，各种钥匙数量+1");
        break;
    case 71:
        levelUp(1);
        QMessageBox::information(nullptr,"道具","等级提升一级");
        break;
    case 72://大金币
        money+=300;
        QMessageBox::information(nullptr,"道具","金币+300");
        break;
    case 73://十字架
        hasTen=true;
        QMessageBox::information(nullptr,"道具","获得十字架，可交给仙子");
        break;
    case 74:
        hasPan=true;
        QMessageBox::information(nullptr,"道具","风之罗盘，按j可转送任意经过的楼层");
        break;
    case 75:
        _attack+=70;
        QMessageBox::information(nullptr,"道具","获得青锋剑，攻击+70");
        break;
    case 76:
        _defend+=85;
        QMessageBox::information(nullptr,"道具","获得黄金盾，防御+85");
        break;
    case 77:
        hasPick=true;
        QMessageBox::information(nullptr,"道具","获得锄头,将其交给4楼的小偷");
        break;
    case 78:
        _hp*=2;
        QMessageBox::information(nullptr,"道具","血量翻倍");
        break;
    case 79:
        _attack+=150;
        QMessageBox::information(nullptr,"道具","获得神圣剑，攻击+150");
        break;
    case 80:
        _defend+=190;
        QMessageBox::information(nullptr,"道具","获得神圣盾，防御+180");
        break;
    case 81:
        hasQuery=true;
        QMessageBox::information(nullptr,"道具","获得圣光徽，按H可查看本层怪物属性");
        break;
    }
    s.isGet=true;
}

bool hero::openDoor(door &d)
{
    if(d.isOpen)
        return false;
    switch (d._type) {
    case 51:
        if(keyY<1)
            return false;
        keyY-=1;
        break;
    case 52:
        if(keyB<1)
            return false;
        keyB-=1;
        break;
    case 53:
        if(keyR<1)
            return false;
        keyR-=1;
        break;
    }
    d.isOpen=true;
    return true;
}

bool hero::fight(monster &m)
{
    if(m._isdead)
        return false;

    if(m._type==30){//红衣魔王剧情
        QMessageBox::warning(nullptr,"红衣魔王","愚蠢的人类，停手吧");
        QMessageBox::information(nullptr,"英雄","少废话,我一定要救出公主");
    }

    if(m._type==32){//19层冥灵魔王剧情
        QMessageBox::information(nullptr,"英雄","大魔王受死吧");
        QMessageBox::information(nullptr,"冥灵魔王","哈哈哈，别以为有了碟仙的力量就能打败我");
        QMessageBox::information(nullptr,"英雄","废话少说，去死吧");
    }
    if(_attack<=m._defend)
        return false;
    int temp=0;
    int temp1=m._Hp;
    temp+=m._magicHurt;

    if(m._type==17){
        temp+=0.25*_hp;
    }

    if(m._type==26){
        temp+=_hp/3;
    }

    while(temp1>0){
        temp1-=_attack-m._defend;
        if(temp1<=0)
            break;
        if(m._Attack<=_defend)
            temp+=0;
        else{
            temp+=m._Attack-_defend;
        }
    }
    if(temp>=_hp)
        return false;
    _hp-=temp;
    money+=m._RewardM;
    exp+=m._RewardE;
    m._isdead=true;
    return true;
}


